package com.heima.behavior.service.impl;

import com.heima.behavior.dto.BehaviorDto;
import com.heima.behavior.entity.ApBehaviorEntry;
import com.heima.behavior.entity.ApUnlikesBehavior;
import com.heima.behavior.mapper.ApUnlikesBehaviorMapper;
import com.heima.behavior.service.IApBehaviorEntryService;
import com.heima.behavior.service.IApUnlikesBehaviorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.common.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * APP不喜欢行为表 服务实现类
 * </p>
 *
 * @author syl
 * @since 2022-07-05
 */
@Service
public class ApUnlikesBehaviorServiceImpl extends ServiceImpl<ApUnlikesBehaviorMapper, ApUnlikesBehavior> implements IApUnlikesBehaviorService {
    @Autowired
    private IApBehaviorEntryService apBehaviorEntryService;


    @Override
    public ResponseResult saveUnlikesBehavior(BehaviorDto dto) {
        ApBehaviorEntry entry = apBehaviorEntryService.getBehaviorEntryByUserIdOrEquipmentId(dto.getUserId(), dto.getEquipmentId());

        ApUnlikesBehavior apUnlikesBehavior = new ApUnlikesBehavior();
        apUnlikesBehavior.setEntryId(entry.getId());
        apUnlikesBehavior.setArticleId(dto.getArticleId());
        apUnlikesBehavior.setOperation(dto.getOperation());
        apUnlikesBehavior.setCreatedTime(new Date());
        this.save(apUnlikesBehavior);

        return ResponseResult.okResult();
    }
}
